package com.lmx.repoDomain.tmodel;

import io.katharsis.resource.annotations.JsonApiIncludeByDefault;
import io.katharsis.resource.annotations.JsonApiResource;
import io.katharsis.resource.annotations.JsonApiToMany;
import io.katharsis.resource.annotations.JsonApiToOne;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 *
 * 服务以及用药执行
 */
@JsonApiResource(type = "serviceexe")
public class ServicesExe extends BaseEntity implements Comparable<ServicesExe> {

	private CustomerDrugProjectExe drugExe;

	private NursingPlanExecute itemExe;

	private Long dateTab;

	private String dateTabString;
	
	private String dateString;
	
	public String getDateString() {
		String dateString = null;
		Long longTime = new Long(this.getDate());
		Date date = new Date(longTime * 1000);
		SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd");
		dateString = sim.format(date);
		return dateString;
	}

	public void setDateString(String dateString) {
		this.dateString = dateString;
	}

	public String getDateTabString() {
		return dateTabString;
	}

	public void setDateTabString(String dateTabString) {
		this.dateTabString = dateTabString;
	}

	public Long getDateTab() {
		return dateTab;
	}

	public void setDateTab(Long dateTab) {
		this.dateTab = dateTab;
	}

	@JsonApiToMany
	@JsonApiIncludeByDefault
	public NursingPlanExecute getItemExe() {
		return itemExe;
	}

	public void setItemExe(NursingPlanExecute itemExe) {
		this.itemExe = itemExe;
	}

	@JsonApiToOne
	@JsonApiIncludeByDefault
	public CustomerDrugProjectExe getDrugExe() {
		return drugExe;
	}

	public void setDrugExe(CustomerDrugProjectExe drugExe) {
		this.drugExe = drugExe;
	}

	@Override
	public int compareTo(ServicesExe o) {
		long date1 = this.getDate();

		long date2 = o.getDate();

		if (date1 == date2) {
			return 0;
		}
		if (date1 < date2) {
			return 1;
		}
		if (date1 > date2) {
			return -1;
		}
		return 0;

	}

	public long getDate() {
		if (this.getItemExe() != null) {
			return this.getItemExe().getCreateDateTime();
		}
		if (this.getDrugExe() != null) {
			return this.getDrugExe().getCreateDateTime();
		}
		if (this.getDateTab() != null) {
			return this.getDateTab();
		}
		return 0;
	}

}
